package edu.hnnu.sport_event.utils;

import java.util.HashMap;
import java.util.Map;

public class Result {

    public static final int SUCCESS = 200;
    public static final int ERROR = 500;

    private int code;         // 响应码
    private String message;   // 响应信息
    private int errorCode;    // 错误码
    private Map<String, Object> data = new HashMap<>();

    public Result() {}
    public Result(String message, int code) {
        this(message, code, 0);
    }
    public Result(String message, int code, int data) {
        this.message = message;
        this.code = code;
        this.errorCode = data;
    }

    public static Result error(String message, int errorCode) {
        return new Result(message, ERROR, errorCode);
    }
    public static Result error(String message) {
        return new Result(message, ERROR);
    }
    public static Result success(String message) {
        return new Result(message, SUCCESS);
    }
    public static Result success(String message, int uid) {
        return new Result(message, SUCCESS, uid);
    }

    public Result addAttribute(String key, Object value) {
        if (null == data) data = new HashMap<>();
        data.put(key, value);
        return this;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public Map<String, Object> getData() {
        return this.data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
